home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 050a / tse_mac1.zip / SAVER.ZIP / SAVER.S < prev   
Text File  |  1993-04-20  |  5KB  |  179 lines

  1. /**********************************************************************
  2.            ┌───────────────────────────────────────────────┐
  3.            │        Released into the public domain        │
  4.            │  20 April 1993 by the author, Rick VanNorman  │
  5.            └───────────────────────────────────────────────┘
  6.  
  7. This set of macros will save and restore editor status, including all
  8. bookmarks set and files in the edit ring.
  9.  
  10. Editor status, including video mode, bookmarks, and all files currently
  11. being edited, is saved on exit via mSaveStatAndExit().
  12.  
  13. On startup, if there are no parameters on the command tail and the file
  14. STATUS.TSE is available, the full editor status described by STATUS.TSE
  15. will be restored.  If no command tail and no STATUS.TSE the user will be
  16. prompted for a file to edit (as normal TSE).  If a command tail is
  17. present, STATUS.TSE is ignored and the editor is started fresh with the
  18. files specified by the user.
  19.  
  20. The startup sequence requires access to the dos command tail, gained via
  21. the assembler routine GETCMDLINE in the file CMDLINE.ASM.  It will work
  22. only on DOS v3.0 and greater.
  23.  
  24. Thanks to Semware for the ability to access executable binary routines
  25. and enough documentation to use them.
  26.  
  27. These routines could be extended to rebuild a multi-window display,
  28. restore command histories, or almost everything else; I don't need that
  29. level of functionality so I won't do it.
  30.  
  31. 20 April 1993
  32. Rick VanNorman
  33. Route 1 Box 294
  34. Glenwood, WV 25520
  35.  
  36. **********************************************************************/
  37.  
  38. // include the binary file to access the command tail
  39. binary "cmdline.bin"
  40.     integer proc GetCmdLine(var string cmdline) :   0
  41. end
  42.  
  43. // restore a file for editing
  44. proc RestoreEdit()
  45.         integer theline,therow
  46.  
  47.         theline = val(GetText(8,5))
  48.         therow  = val(GetText(14,2))
  49.         editfile(GetText(17,64))
  50.         GotoLine(theline)
  51.         ScrollToRow(therow)
  52. end
  53.  
  54.  
  55. // restore a bookmark
  56. proc RestoreMark()
  57.         string themark[1]
  58.  
  59.         themark = gettext(6,1)
  60.         restoreedit()
  61.         PlaceMark(themark)
  62. end
  63.  
  64.  
  65. // restore the video mode
  66. proc RestoreVid()
  67.         set(CurrVideoMode,Val(GetText(8,5)))
  68. end
  69.  
  70. // parse the STATUS.TSE file and restore the status of the editor
  71. proc mRestoreEdit()
  72.         integer statfile,i=1
  73.         string mode[4]
  74.  
  75.         editfile("status.tse")
  76.         statfile = getbufferid()
  77.         while (i <= numlines())
  78.                 gotoline(i)
  79.                 mode = gettext(1,4)
  80.                 case mode
  81.                         when "edit"
  82.                                 RestoreEdit()
  83.                         when "mark"
  84.                                 RestoreMark()
  85.                         when "vid "
  86.                                 RestoreVid()
  87.                 endcase
  88.                 gotobufferid(statfile)
  89.                 i = i + 1
  90.         endwhile
  91.         abandonfile()
  92. end
  93.  
  94.  
  95. // if there is a file STATUS.TSE, use it to restore the editor
  96. proc mLoadFromStat()
  97.  
  98.         if fileexists("status.tse")
  99.                 mrestoreedit()
  100.         endif
  101. end
  102.  
  103.  
  104. // save the current bookmarks. flist is the buffer id of the output file
  105. proc mSaveMarks(integer flist)
  106.     integer i=1
  107.     string themark[1]
  108.     string s[80]
  109.  
  110.     while i <= 26
  111.         themark = (Chr(Asc('a') + i - 1))
  112.         if GotoMark(themark)
  113.             // if mark there, add it to list of marks
  114.             s = Format('mark ', themark:1,' ', currline():5,' ',
  115.                        currrow():2,' ',currfilename())
  116.             GotoBufferId(flist)
  117.             AddLine(s)
  118.         endif
  119.         i = i + 1
  120.     endwhile
  121. end
  122.  
  123.  
  124. // save the currently open files and their positions
  125. proc mSavePositions(integer flist, integer start)
  126.         integer temp
  127.         string s[80]
  128.  
  129.         gotobufferid(start)
  130.         repeat
  131.                 if (query(buffertype) == _NORMAL_)
  132.                         temp = getbufferid()
  133.                         s = format('edit   ',currline():5,' ',currrow():2,' ',currfilename())
  134.                         gotobufferid(flist)
  135.                         addline(s)
  136.                         gotobufferid(temp)
  137.                 endif
  138.                 nextfile()
  139.         until (getbufferid() == start)
  140.         gotobufferid(flist)
  141. end
  142.  
  143.  
  144. // save all status and save all files and exit
  145. proc mSaveStatAndExit ()
  146.         integer start, flist, temp
  147.         string s[80]
  148.  
  149.         start = getbufferid()
  150.         flist = createtempbuffer()
  151.         s = format('vid   ',query(currvideomode):5)
  152.         addline(s)
  153.         mSaveMarks(flist)
  154.         mSavePositions(flist,start)
  155.         saveas("status.tse",_OVERWRITE_)
  156.         abandonfile()
  157.         saveallandexit()
  158. end
  159.  
  160. // --------------------------------------------------------------------
  161.  
  162. // this is the modified WHENLOADED()
  163.  
  164. proc WhenLoaded()
  165.     integer cid = GetBufferId()
  166.     string  cmdline[128] = ''
  167.  
  168.     pick_buffer = CreateTempBuffer()
  169.     GotoBufferId(cid)
  170.     Hook(_ON_CHANGING_FILES_, OnChangingFiles)
  171.     Hook(_ON_FIRST_EDIT_, OnFirstEdit)
  172.  
  173.     getcmdline(cmdline)
  174.     if (length(cmdline) == 0)
  175.         mloadfromstat()
  176.     endif
  177. end
  178.  
  179.